﻿namespace ChinaUnicom.Tasks
{
    using System;
    using ChinaUnicom.Models;
    using ChinaUnicom.Schedule;
    using System.Net;

    internal class FeeTask : ITask
    {
        public Fee Fee { get; private set; }

        public FeeTask()
        {
            Fee = new Fee();
        }

        public void Start()
        {
            if (Started != null)
            {
                Started(this, EventArgs.Empty);
            }

            Factory.Operation.RequestFeeInfo(x =>
            {
                if (x.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    Fee.Items = Factory.Parser.Parse(x.Result, InfoType.Fee);

                    if (Completed != null)
                    {
                        Completed(this, EventArgs.Empty);
                    }
                }
            });
        }

        public int Pending
        {
            get { return 10; }
        }

        public event EventHandler Completed;


        public event EventHandler Started;
    }
}
